<template>
  <normal-layout>
    <el-tabs style="margin: 10px" tab-position="left">
      <el-tab-pane label="个人信息">
        <el-card>
          <div style="margin: 50px; width: 50%; font-size: 24px; display: inline">
            <p>编号：{{personInfo.sno}}</p>
            <el-divider></el-divider>
            <p>姓名：{{personInfo.name}}</p>
            <el-divider></el-divider>
            <p>性别：{{personInfo.sex}}</p>
            <el-divider></el-divider>
            <p>年龄：{{personInfo.age}}</p>
            <el-divider></el-divider>
            <p>联系方式：{{personInfo.tel}}</p>
            <el-divider></el-divider>
            <p>职位：{{personInfo.position}}</p>
            <el-divider></el-divider>
            <p>当月业绩：<el-progress type="circle" :percentage="progress"></el-progress></p><span>目标业绩： {{personInfo.target}}</span>
            <el-divider></el-divider>
          </div>
        </el-card>
      </el-tab-pane>
      <el-tab-pane label="修改密码">
        <el-form>
          <el-form-item label="输入新密码">
            <el-input style="width: 50%" show-password v-model="newPasswordi"></el-input>
          </el-form-item>
          <el-form-item label="重复新密码">
            <el-input style="width: 50%" show-password v-model="newPasswordj"></el-input>
          </el-form-item>
          <el-button type="primary" @click="modifyPassword">修改密码</el-button>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </normal-layout>
</template>

<script>
  import NormalLayout from "../../layouts/NormalLayout";
  export default {
    components: {NormalLayout},
    data(){
      return{
        personInfo:{},
        progress:0,
        newPasswordi:'',
        newPasswordj:''
      }
    },
    mounted() {
      this.getData();
    },
    methods:{
      getData(){
        this.$axios.get('/get_my').then((res)=>{
          this.personInfo=res.data[0];
          console.log(res);
          this.progress=(this.personInfo.turnover/this.personInfo.target)*100;
          console.log(this.progress);
        })
      },
      modifyPassword(){
        if(this.newPasswordi===this.newPasswordj!==''){
          let mydata={
            password:this.newPasswordi,
          }
          console.log(mydata);
          this.$axios.post('modify_my',mydata).then((res)=>{
            if(res.data==='1'){
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.$router.push({path:'/'});
            }else {
              this.$message({
                type: 'error',
                message: '操作失败!'
              });
            }
          })
        }else if (this.newPasswordi===''){
          this.$message({
            type: 'error',
            message: '新密码不能为空!'
          });
        }else{
          this.$message({
            type: 'error',
            message: '新密码须与旧密码相同!'
          });
        }

      },
    }
  }
</script>

<style scoped>

</style>
